local japi = require "jass.japi"
local slk = require "jass.slk"
local xlsx = ac.excel['单位\\unit.xlsx']
local symbol = require 'symbol.unit'

-- 直接把表格加到ini文件里面
local function echo(...)
    if package.local_test then 
        print(...)
    end 
end 

if xlsx and xlsx['基础属性'] and xlsx['成长属性'] and xlsx['自定义值'] then 
    for name, data in pairs(xlsx['基础属性']) do 
        local info = ac.lni('unit', name)
        if info then 
            info.state = data
        end 
    end 
    for name, data in pairs(xlsx['成长属性']) do 
        local info = ac.lni('unit', name)
        if info then 
            info.upgrade = data
        end 
    end 
    for name, data in pairs(xlsx['自定义值']) do 
        local info = ac.lni('unit', name)
        if info then 
            for k,v in pairs(data) do 
                -- echo(name, "->自定义值", k, v)
                info[k] = v 
            end 
        end 
    end 
end 

for name, unitcode in pairs(symbol) do 
    if type(name) == "string" and type(unitcode) == 'number' then 
        local data = ac.lni("unit", name)
        if data then 
            japi.SetUnitBaseName(unitcode, data.name)
            japi.SetUnitBaseProperName(unitcode, data.name)
            japi.SetUnitBaseArt(unitcode, data.art)
            japi.SetUnitBaseTip(unitcode, data.tip)
            japi.SetUnitBaseUbertip(unitcode, data.ubertip)
            data.art = data.art or slk.unit[FourCC(unitcode)]["Art"]
            data.scale = tonumber(data.scale or slk.unit[FourCC(unitcode)]["modelScale"])
        end 
    end 
end 